home *** CD-ROM | disk | FTP | other *** search
-
- /*
- ** This source code was written by Tim Endres
- ** Email: time@ice.com.
- ** USMail: 8840 Main Street, Whitmore Lake, MI 48189
- **
- ** Some portions of this application utilize sources
- ** that are copyrighted by ICE Engineering, Inc., and
- ** ICE Engineering retains all rights to those sources.
- **
- ** Neither ICE Engineering, Inc., nor Tim Endres,
- ** warrants this source code for any reason, and neither
- ** party assumes any responsbility for the use of these
- ** sources, libraries, or applications. The user of these
- ** sources and binaries assumes all responsbilities for
- ** any resulting consequences.
- */
-
- #pragma segment MacBinary
-
- #include "tickle.h"
- #include "mb.h"
-
- #define MAC_BINARY_BLK_SIZE 128
-
- static char hdrbuffer[MAC_BINARY_BLK_SIZE];
- static char buffer[MAC_BINARY_BLK_SIZE];
-
- long unpack_long();
-
- #ifdef TCLAPPL
-
- DoMacBinary(direction)
- int direction;
- {
- Point mypoint;
- SFReply inreply, outreply;
- SFTypeList mytypes;
- short inref, outref, myerr, num_types;
- F_BLK_PTR hdr_ptr;
-
- if (direction == MAC_FILE) {
- /* Convert MacBinary file into a Macintosh file. */
- mypoint.h = mypoint.v = 75;
- #ifdef NEVER_DEFINED
- mytypes[0] = (ResType)'MacB';
- num_types = 1;
- if (CheckOption())
- #endif
- num_types = -1;
-
- MyGetFile(mypoint, "\pMacBinary File:", NULL, num_types, mytypes, NULL, &inreply);
- if (inreply.good) {
- SetVol(NULL, inreply.vRefNum);
- myerr = FSOpen(inreply.fName, inreply.vRefNum, &inref);
- if (myerr != noErr) {
- p2cstr(inreply.fName);
- message_alert("Error #%d opening file '%s'.", myerr, inreply.fName);
- }
- else {
- memset(hdrbuffer, 0, MAC_BINARY_BLK_SIZE);
- UBegYield();
- myerr = extract_macbinary_header(inref, hdrbuffer);
- if (myerr != noErr) {
- message_alert("Error #%d reading MacBinary header information.", myerr);
- }
- else {
- hdr_ptr = (F_BLK_PTR) &hdrbuffer[0];
- MyPutFile(mypoint, "\pMacintosh File:", &hdr_ptr->nlen, NULL, &outreply);
- if (outreply.good) {
- SetFPos(inref, fsFromStart, 0);
- myerr = extract_macbinary(inref, outreply.vRefNum, outreply.fName);
- if (myerr != noErr) {
- message_alert("Error #%d extracting Macintosh file.", myerr);
- }
- else
- linef("MacBinary file converted to Macintosh file.");
- }
- }
- FSClose(inref);
- UEndYield();
- }
- }
- }
- else {
- /* Convert Macintosh file into a MacBinary file. */
- mypoint.h = mypoint.v = 75;
- MyGetFile(mypoint, "\pMacintosh File:", NULL, -1, mytypes, NULL, &inreply);
- if (inreply.good) {
- sprintf(temp_str, "%.*s.mb", inreply.fName[0], &inreply.fName[1]);
- c2pstr(temp_str);
- MyPutFile(mypoint, "\pMacBinary File:", temp_str, NULL, &outreply);
- if (outreply.good) {
- SetVol(NULL, outreply.vRefNum);
- myerr = Create(outreply.fName, outreply.vRefNum, APPL_TYPE, (ResType)'MacB');
- if (myerr == dupFNErr)
- {
- p2cstr(outreply.fName);
- file_type(outreply.fName, (ResType)'MacB', APPL_TYPE);
- c2pstr(outreply.fName);
- }
- myerr = FSOpen(outreply.fName, outreply.vRefNum, &outref);
- if (myerr != noErr) {
- p2cstr(outreply.fName);
- message_alert("Error #%d opening MacBinary file '%s'.",
- myerr, outreply.fName);
- }
- else {
- UBegYield();
- myerr = insert_macbinary(outref, inreply.fName, inreply.vRefNum, 0);
- if (myerr != noErr)
- message_alert("Error #%d converting Macintosh file to MacBinary.", myerr);
- else
- linef("Macintosh file converted to MacBinary file.");
- FSClose(outref);
- UEndYield();
- }
- }
- }
- }
-
- UInitCursor();
- }
-
- #endif /* TCLAPPL */
-
-
- insert_macbinary(outref, name, vrefnum, dirid)
- short outref;
- char *name; /* Pascal String */
- short vrefnum;
- long dirid;
- {
- char *ptr;
- HParamBlockRec pb;
- int i, blocks, residue;
- long datalen, rsrclen, bytes;
- short dataref, rsrcref, myerr, result = noErr;
- char savevname[255];
- char cfilename[255];
- short savevref;
- F_BLK_PTR the_hdr;
-
- GetVol(savevname, &savevref);
- SetVol(NULL, vrefnum);
-
- strncpy(cfilename, &name[1], name[0]);
- cfilename[name[0]] = '\0';
-
- pb.fileParam.ioCompletion = 0;
- pb.fileParam.ioNamePtr = name;
- pb.fileParam.ioVRefNum = vrefnum;
- pb.fileParam.ioDirID = dirid;
- pb.fileParam.ioFVersNum = 0;
- pb.fileParam.ioFDirIndex = 0;
- PBHGetFInfo(&pb, false);
- if (pb.fileParam.ioResult != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Could not get information about file '%s'. Error #%d.\n",
- cfilename, pb.fileParam.ioResult);
- return pb.fileParam.ioResult;
- }
-
- RotateCursor(32);
- the_hdr = (F_BLK_PTR) &hdrbuffer[0];
- memset(hdrbuffer, 0, MAC_BINARY_BLK_SIZE);
-
- for (ptr = &name[i = name[0]]; i>0; ptr--,i--)
- if (*ptr == ':') {
- *ptr = (char)( name[0] - (int)(ptr - &name[0]) );
- break;
- }
- if (*ptr > 63) *ptr = (char) 63;
- BlockMove(ptr, &the_hdr->nlen, *ptr + 1);
- if (ptr != &name[0])
- *ptr = ':'; /* Put it back */
-
- BlockMove((Ptr)&pb.fileParam.ioFlFndrInfo.fdLocation, the_hdr->location, sizeof(the_hdr->location));
- BlockMove((Ptr)&pb.fileParam.ioFlFndrInfo.fdType, the_hdr->type, sizeof(the_hdr->type));
- BlockMove((Ptr)&pb.fileParam.ioFlFndrInfo.fdCreator, the_hdr->creator, sizeof(the_hdr->creator));
- the_hdr->protected = ((pb.fileParam.ioFlFndrInfo.fdFlags & 0x40) != 0) ? '\001' : '\0';
- pack_long(pb.fileParam.ioFlLgLen, the_hdr->dflen);
- pack_long(pb.fileParam.ioFlRLgLen, the_hdr->rflen);
- pack_long(pb.fileParam.ioFlCrDat, the_hdr->cdate);
- pack_long(pb.fileParam.ioFlMdDat, the_hdr->mdate);
- the_hdr->zero1 = 0;
- the_hdr->zero2 = 0;
- the_hdr->zero3 = 0;
-
- datalen = pb.fileParam.ioFlLgLen;
- rsrclen = pb.fileParam.ioFlRLgLen;
-
- RotateCursor(32);
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(outref, &bytes, hdrbuffer);
- if (myerr != noErr || bytes != MAC_BINARY_BLK_SIZE) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing MacBinary header data.\n",
- ((myerr != noErr) ? myerr : writErr));
- return ((myerr != noErr) ? myerr : writErr);
- }
-
- RotateCursor(32);
- DoYield();
- if (datalen > 0) {
- SetVol(NULL, vrefnum);
- pb.ioParam.ioPermssn = fsRdPerm;
- pb.ioParam.ioMisc = NULL;
- pb.fileParam.ioDirID = dirid;
- myerr = PBHOpen(&pb, false);
- if (myerr != noErr) {
- SetVol(NULL, savevref);
- SysBeep(0);
- UUDEBUG(0, "Could not open file '%s'. Error #%d.\n", cfilename, myerr);
- result = pb.ioParam.ioResult;
- }
- else {
- dataref = pb.ioParam.ioRefNum;
-
- blocks = datalen / MAC_BINARY_BLK_SIZE;
- residue = datalen % MAC_BINARY_BLK_SIZE;
- while (blocks-- && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(dataref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading file '%s'. [D]\n", myerr, cfilename);
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(outref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to output file.\n", myerr);
- }
- }
- }
- if (residue > 0 && result == noErr) {
- RotateCursor(32);
- DoYield();
- for (ptr=buffer,i=0; i<MAC_BINARY_BLK_SIZE; i++) *ptr++ = '\0';
- bytes = residue;
- myerr = FSRead(dataref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading file '%s' [D].\n", myerr, cfilename);
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(outref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to output file.\n", myerr);
- }
- }
- }
-
- WatchCursorOn();
- PBClose((ParmBlkPtr) &pb, false);
- }
- }
-
- RotateCursor(32);
- if (rsrclen > 0 && result == noErr) {
- SetVol(NULL, vrefnum);
- pb.fileParam.ioDirID = dirid;
- myerr = PBHOpenRF(&pb, false);
- if (myerr != noErr) {
- SetVol(NULL, savevref);
- SysBeep(0);
- UUDEBUG(0, "Could not open resource file '%s'. Error #%d\n", cfilename, myerr);
- result = pb.ioParam.ioResult;
- }
- else {
- rsrcref = pb.ioParam.ioRefNum;
-
- blocks = rsrclen / MAC_BINARY_BLK_SIZE;
- residue = rsrclen % MAC_BINARY_BLK_SIZE;
- while (blocks-- && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(rsrcref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading file '%s'. [R]\n", myerr, cfilename);
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(outref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to output file.\n", myerr);
- }
- }
- }
- if (residue > 0 && result == noErr) {
- RotateCursor(32);
- DoYield();
- for (ptr=buffer,i=0; i<MAC_BINARY_BLK_SIZE; i++) *ptr++ = '\0';
- bytes = residue;
- myerr = FSRead(rsrcref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading file '%s'. [R]\n", myerr, cfilename);
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(outref, &bytes, buffer);
- if (myerr != noErr) {
- result = myerr;
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to output file.\n", myerr);
- }
- }
- }
-
- WatchCursorOn();
- PBClose((ParmBlkPtr) &pb, false);
- }
- }
-
- UInitCursor();
- SetVol(NULL, savevref);
-
- return result;
- }
-
-
- extract_macbinary(inref, vrefnum, outfile)
- short inref;
- short vrefnum;
- char *outfile; /* P-String, If NULL, use header. */
- {
- char *ptr;
- ParamBlockRec pb;
- int i, blocks, residue;
- long datalen, rsrclen, bytes;
- short dataref, rsrcref, myerr, result = noErr;
- char name[256];
- F_BLK_PTR the_hdr;
- char savevname[255];
- char cfilename[255];
- short savevref;
-
- GetVol(savevname, &savevref);
- SetVol(NULL, vrefnum);
-
- RotateCursor(32);
- DoYield();
-
- the_hdr = (F_BLK_PTR) &hdrbuffer[0];
- for (ptr=hdrbuffer,i=0; i<MAC_BINARY_BLK_SIZE; i++) *ptr++ = '\0';
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, hdrbuffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "extract_macbinary: Error #%d reading header.\n", myerr);
- return myerr;
- }
-
- datalen = unpack_long(the_hdr->dflen);
- rsrclen = unpack_long(the_hdr->rflen);
-
- if (outfile != NULL) {
- BlockMove(outfile, name, outfile[0] + 1);
- }
- else {
- BlockMove(the_hdr->name, name, the_hdr->name[0] + 1);
- }
- strncpy(cfilename, &name[1], name[0]);
- cfilename[name[0]] = '\0';
-
- RotateCursor(32);
- DoYield();
-
- pb.ioParam.ioCompletion = 0;
- pb.ioParam.ioNamePtr = name;
- pb.ioParam.ioVRefNum = vrefnum;
- pb.ioParam.ioVersNum = 0;
- pb.ioParam.ioPermssn = fsWrPerm;
- pb.ioParam.ioMisc = NULL;
-
- for ( i = 'B' ; i <= 'Z' ; ) {
- myerr = PBCreate(&pb, FALSE);
- if (myerr == dupFNErr) {
- if (i == 'B') {
- name[++name[0]] = '-';
- name[++name[0]] = i;
- }
- name[name[0]] = i++;
- continue;
- }
- else
- break;
- }
-
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "extract_macbinary: Error #%d creating '%s'.\n", myerr, cfilename);
- return myerr;
- }
-
- linef("Extracting Macintosh file '%s'...", cfilename);
-
- RotateCursor(32);
- if (datalen > 0 && result == noErr) {
- SetVol(NULL, vrefnum);
- myerr = PBOpen(&pb, false);
- if (myerr != noErr) {
- SetVol(NULL, savevref);
- SysBeep(0);
- UUDEBUG(0, "Error #%d opening data fork of '%s'.\n", myerr, cfilename);
- result = pb.ioParam.ioResult;
- }
- else {
- dataref = pb.ioParam.ioRefNum;
- blocks = datalen / MAC_BINARY_BLK_SIZE;
- residue = datalen % MAC_BINARY_BLK_SIZE;
- while (blocks-- && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading input file.\n", myerr);
- result = myerr;
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(dataref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to file '%s'. [D]\n", myerr, cfilename);
- result = myerr;
- }
- }
- }
- if (residue > 0 && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d reading input file.\n", myerr);
- result = myerr;
- }
- else {
- bytes = residue;
- myerr = FSWrite(dataref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to file '%s'. [D]\n", myerr, cfilename);
- result = myerr;
- }
- }
- }
-
- WatchCursorOn();
- PBClose(&pb, false);
- }
- }
-
- RotateCursor(32);
- if (rsrclen > 0 && result == noErr) {
- SetVol(NULL, vrefnum);
- myerr = PBOpenRF(&pb, false);
- if (myerr != noErr) {
- UUDEBUG(0, "Error #%d opening resource fork of '%s'.\n", myerr, cfilename);
- result = pb.ioParam.ioResult;
- }
- else {
- rsrcref = pb.ioParam.ioRefNum;
- blocks = rsrclen / MAC_BINARY_BLK_SIZE;
- residue = rsrclen % MAC_BINARY_BLK_SIZE;
- while (blocks-- && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, buffer);
- if (myerr != noErr) {
- UUDEBUG(0, "Error #%d reading input file.\n", myerr);
- result = myerr;
- }
- else {
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSWrite(rsrcref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to file '%s'. [R]\n", myerr, cfilename);
- result = myerr;
- }
- }
- }
- if (residue > 0 && result == noErr) {
- RotateCursor(32);
- DoYield();
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, buffer);
- if (myerr != noErr) {
- UUDEBUG(0, "Error #%d reading input file.\n", myerr);
- result = myerr;
- }
- else {
- bytes = residue;
- myerr = FSWrite(rsrcref, &bytes, buffer);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d writing to file '%s'. [R]\n", myerr, cfilename);
- result = myerr;
- }
- }
- }
-
- WatchCursorOn();
- PBClose(&pb, false);
- }
- }
-
- WatchCursorOn();
- DoYield();
- SetVol(NULL, vrefnum);
- if (result == noErr) {
- pb.fileParam.ioFDirIndex = 0;
- myerr = PBGetFInfo(&pb, false);
-
- pb.fileParam.ioFlFndrInfo.fdType = unpack_long(the_hdr->type);
- pb.fileParam.ioFlFndrInfo.fdCreator = unpack_long(the_hdr->creator);
- pb.fileParam.ioFlFndrInfo.fdFlags |= (short) the_hdr->flags;
- pb.fileParam.ioFlFndrInfo.fdLocation.h = 16;
- pb.fileParam.ioFlFndrInfo.fdLocation.v = 16;
- pb.fileParam.ioFlMdDat = unpack_long(the_hdr->mdate);
- pb.fileParam.ioFlCrDat = unpack_long(the_hdr->cdate);
-
- myerr = PBSetFInfo(&pb, false);
- if (myerr != noErr) {
- SysBeep(0);
- UUDEBUG(0, "Error #%d setting file info for '%s'.\n", myerr, cfilename);
- result = myerr;
- }
-
- DoYield();
- UUDEBUG(0, "EXTRACTED <%s> via MacBinary\n", cfilename);
- FlushVol(NULL, vrefnum);
- }
- else {
- myerr = PBDelete(&pb, FALSE);
- }
-
- SetVol(NULL, savevref);
- return result;
- }
-
- extract_macbinary_header(inref, hdr_ptr)
- short inref;
- char *hdr_ptr;
- {
- long bytes;
- short myerr;
-
- bytes = MAC_BINARY_BLK_SIZE;
- myerr = FSRead(inref, &bytes, (Ptr)hdr_ptr);
-
- return myerr;
- }
-
- pack_long(mylong, to)
- register long mylong;
- register unsigned char *to;
- {
- *to++ = (unsigned char) (mylong >> 24) & 0x000000FF;
- *to++ = (unsigned char) (mylong >> 16) & 0x000000FF;
- *to++ = (unsigned char) (mylong >> 8) & 0x000000FF;
- *to++ = (unsigned char) mylong & 0x000000FF;
- }
-
- long
- unpack_long(from)
- register unsigned char *from;
- {
- unsigned long mylong;
-
- mylong = (unsigned long) *from++;
- mylong = (mylong << 8) + (unsigned long) *from++;
- mylong = (mylong << 8) + (unsigned long) *from++;
- mylong = (mylong << 8) + (unsigned long) *from;
-
- return mylong;
- }
-
-
- int
- Cmd_UnMacBinary(clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- short wdrefnum;
- int result = TCL_OK, push_err;
- char outname[256];
- char pascal_name[256];
- short inref, myerr;
- F_BLK_PTR hdr_ptr;
- FInfo finfo;
- extern int macintoshErr;
- #pragma unused (clientData)
-
- if (argc < 2 || argc > 3)
- {
- Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- " mbfilename ?macfilename?\"", (char *) NULL);
- return TCL_ERROR;
- }
-
- myerr = TclMac_CWDCreateWD(&wdrefnum);
- if (myerr != noErr)
- {
- Tcl_AppendResult(interp, "could not create working directory - ",
- Tcl_MacGetError(interp, result), NULL);
- return TCL_ERROR;
- }
-
- push_err = TclMac_CWDPushVol();
-
- strcpy(pascal_name, argv[1]);
- c2pstr(pascal_name);
- myerr = FSOpen(pascal_name, wdrefnum, &inref);
- if (myerr != noErr)
- {
- Tcl_AppendResult(interp, "error opening file \"",
- argv[1], "\" ", Tcl_MacGetError(interp, myerr), (char *) NULL);
- result = TCL_ERROR;
- }
- else {
- memset(hdrbuffer, 0, MAC_BINARY_BLK_SIZE);
- UBegYield();
- myerr = extract_macbinary_header(inref, hdrbuffer);
- if (myerr != noErr)
- {
- Tcl_AppendResult(interp, "error reading MacBinary header info ",
- Tcl_MacGetError(interp, myerr), (char *) NULL);
- result = TCL_ERROR;
- }
- else
- {
- hdr_ptr = (F_BLK_PTR) &hdrbuffer[0];
- if (argc > 2)
- {
- strcpy(outname, argv[2]);
- c2pstr(outname);
- }
- else
- {
- BlockMove(&hdr_ptr->nlen, outname, hdr_ptr->nlen+1);
- }
-
- myerr = GetFInfo(outname, wdrefnum, &finfo);
- #ifdef NEVER_DEFINED
- /*
- ** UNDONE should warn and quit without a "-f" flag..
- */
- if (myerr == noErr) /* File EXISTS!!! */
- outname[++outname[0]] = '1';
- while (myerr == noErr)
- {
- /* File EXISTS!!! */
- outname[outname[0]]++;
- myerr = GetFInfo(outname, wdrefnum, &finfo);
- }
- #endif
-
- SetFPos(inref, fsFromStart, 0);
- myerr = extract_macbinary(inref, wdrefnum, outname);
- if (myerr != noErr)
- {
- p2cstr(outname);
- Tcl_AppendResult(interp, "error extracting Macintosh file \"",
- outname, "\" ", Tcl_MacGetError(interp, myerr), NULL);
- result = TCL_ERROR;
- }
- }
-
- FSClose(inref);
- UEndYield();
- }
-
- if (push_err == noErr)
- TclMac_CWDPopVol();
-
- TclMac_CWDDisposeWD(wdrefnum);
-
- UInitCursor();
- return result;
- }
-
- #pragma segment AppleEvent
-
- AEUnMacBinary(theFSS)
- FSSpec *theFSS;
- {
- short wdrefnum;
- int result;
- char outname[256];
- short inref, myerr;
- F_BLK_PTR hdr_ptr;
- FInfo finfo;
-
- Feedback("AEUnMacBinary: MacBinary: UnMacBinary '%.*s'",
- theFSS->name[0], &theFSS->name[1]);
-
-
- result = OpenWD(theFSS->vRefNum, theFSS->parID, 'ERIK', &wdrefnum);
- if (result == noErr) {
- myerr = FSOpen(theFSS->name, wdrefnum, &inref);
- if (myerr != noErr) {
- Feedback("AEUnMacBinary: MacBinary: Error #%d opening '%.*s'.",
- myerr, theFSS->name[0], &theFSS->name[1]);
- }
- else {
- memset(hdrbuffer, 0, MAC_BINARY_BLK_SIZE);
- UBegYield();
- myerr = extract_macbinary_header(inref, hdrbuffer);
- if (myerr != noErr) {
- Feedback("Error #%d reading MacBinary header information.", myerr);
- }
- else {
- hdr_ptr = (F_BLK_PTR) &hdrbuffer[0];
- BlockMove(&hdr_ptr->nlen, outname, hdr_ptr->nlen+1);
- myerr = GetFInfo(outname, wdrefnum, &finfo);
- if (myerr == noErr) /* File EXISTS!!! */
- outname[++outname[0]] = '1';
- while (myerr == noErr) {
- /* File EXISTS!!! */
- outname[outname[0]]++;
- myerr = GetFInfo(outname, wdrefnum, &finfo);
- }
-
- SetFPos(inref, fsFromStart, 0);
- myerr = extract_macbinary(inref, wdrefnum, outname);
- if (myerr != noErr) {
- Feedback("Error #%d extracting Macintosh file '%.*s'.",
- myerr, outname[0], &outname[1]);
- }
- else
- Feedback("MacBinary '%.*s' converted to Macintosh '%.*s'.",
- theFSS->name[0], &theFSS->name[1], outname[0], &outname[1]);
- }
-
- FSClose(inref);
- UEndYield();
- }
- }
-
- UInitCursor();
- }
-